package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.ChuanmeiMapper;
import work.xiaohong.gupiao.pojo.Chuanmei;
import work.xiaohong.gupiao.service.ChuanmeiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChuanmeiServiceImpl implements ChuanmeiService {

    @Autowired
    private ChuanmeiMapper chuanmeiMapper;


    /**
     * 条件+分页查询Chuanmei
     * @param chuanmei 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Chuanmei> findPage(Chuanmei chuanmei, int page, int size){
        // 构建查询条件
        QueryWrapper<Chuanmei> queryWrapper = new QueryWrapper<Chuanmei>(chuanmei);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return chuanmeiMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Chuanmei
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Chuanmei> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return chuanmeiMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Chuanmei
     * @param chuanmei
     * @return
     */
    @Override
    public List<Chuanmei> findList(Chuanmei chuanmei){
        // 构建查询条件
        QueryWrapper<Chuanmei> queryWrapper = new QueryWrapper<Chuanmei>(chuanmei);
        // 查询数据
        return chuanmeiMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Chuanmei
     * @param id
     */
    @Override
    public void delete(Integer id){
        chuanmeiMapper.deleteById(id);
    }

    /**
     * 根据ID修改Chuanmei
     * @param chuanmei
     */
    @Override
    public void update(Chuanmei chuanmei){
        chuanmeiMapper.updateById(chuanmei);
    }

    /**
     * 增加Chuanmei
     * @param chuanmei
     */
    @Override
    public void add(Chuanmei chuanmei){
        chuanmeiMapper.insert(chuanmei);
    }

    /**
     * 根据ID查询Chuanmei
     * @param id
     * @return
     */
    @Override
    public Chuanmei findById(Integer id){
        return  chuanmeiMapper.selectById(id);
    }

    /**
     * 查询全部Chuanmei数据
     * @return
     */
    @Override
    public List<Chuanmei> findAll() {
        return chuanmeiMapper.selectList(null);
    }
}
